package com.ruoyi.smart.service;

import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

@Service
public class DeviceDashboardService {

    private final DeviceStatusService deviceStatusService;

    public DeviceDashboardService(DeviceStatusService deviceStatusService) {
        this.deviceStatusService = deviceStatusService;
    }

    /**
     * 获取设备看板数据
     */
    public Map<String, Object> getDashboardData() {
        Map<String, Boolean> deviceStatus = deviceStatusService.getAllDeviceStatus();
        Map<String, Object> statistics = deviceStatusService.getDeviceStatistics();

        Map<String, Object> result = new HashMap<>();
        result.put("deviceStatus", deviceStatus);
        result.put("statistics", statistics);
        result.put("timestamp", System.currentTimeMillis());

        return result;
    }

    /**
     * 获取设备实时状态流
     */
    public Map<String, Object> getDeviceStatusStream() {
        // 这里可以实现WebSocket或SSE推送实时数据
        // 简化版直接返回当前状态
        return getDashboardData();
    }

    /**
     * 获取设备历史状态
     */
    public Map<String, Object> getDeviceHistory(String deviceId, int hours) {
        // 这里可以从数据库或Redis中获取设备历史状态数据
        // 简化版返回空数据
        Map<String, Object> result = new HashMap<>();
        result.put("deviceId", deviceId);
        result.put("hours", hours);
        result.put("data", new ArrayList<>());

        return result;
    }
}
